import 'package:base_flutter/base_flutter.dart';
import 'package:flutter/src/widgets/framework.dart';
import 'package:ls_work/model/meter_reading_model.dart';
import 'package:ls_work/net/response/room_list_data.dart';

import '../../a_yyt/models/floor_list_entity.dart';
import '../../model/building_model.dart';

class MeterReadingRoomViewModel extends BaseListViewModel<RoomListData>{
  MeterReadingRoomViewModel(BuildContext context,{this.buildingId = "",this.floorId = "",this.type}) : super(context);

  var model = MeterReadingModel();
  var buildingId = "";
  var floorId = "";
  final dynamic type;




  @override
  Future<List<RoomListData>> requestListData() async {
    var list =  await model.getMeterRoomList(buildingId, floorId,type: type);
    return list;
  }


  @override
  void onCreated() {
    super.onCreated();
    requestRefresh();
  }

  Future<void> submitReading() async {
    var list =  listItems.where((element) => !element.ordinalNumber.isNullOrEmpty());
    var dataList = list.map((e) => {
      "roomId":e.roomId,
      "ordinalNumber":e.ordinalNumber,
      "iotId":e.iotId,
      "readingTime":e.readingTime,
      "meterReadingType":e.meterReadingType
    }).toList();
    showLoadingDialog(msg: '提交中...');
    try{
      await model.submitMeterReading(dataList);
      hideDialog();
      requestRefresh();
    }catch(e){
      showToast(NetErrorUtils.getNetError(e));
      hideDialog();

    }
  }
}